﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using NSun;
using NBearLite;
using Runda.CMS.Order.Entity;
using Runda.CMS.Order.Repository; 

namespace OrderPortal.Controllers
{
    public class ShippingRequestController : Controller
    {
        private OrderRepository orderRepository = new OrderRepository();

        private ShippingRequestRepository shippingRequestRepository = new ShippingRequestRepository();

        private CustomerRepository customerRepository = new CustomerRepository();

        private InventoryRepository inventoryRepository = new InventoryRepository();

        [HttpGet]
        [RequiresAuthentication]
        public ActionResult Info(String id)
        {
            List<ShippingRequestDetail> shippingRequestDetails = shippingRequestRepository.getDetailByRequestId(id);
            if (shippingRequestDetails != null && shippingRequestDetails.Count > 0)
            {
                ViewData["shippingRequestId"] = shippingRequestDetails[0].requestID;
                ViewData["memo"] = shippingRequestDetails[0].memo;
                ViewData["cDate"] = shippingRequestDetails[0].cdate;
                ViewData["cTime"] = shippingRequestDetails[0].newTime;
                ViewData["cStatus"] = shippingRequestDetails[0].Status;
                //Customer customer = customerRepository.findCustomerByCustomerCode(shippingRequestDetails[0].customerId);
                //ViewData["customerName"] = customer.name;
                ViewData["customerName"] = shippingRequestDetails[0].CusName;
                List<OrderDetail> detais = new List<OrderDetail>();
                foreach (ShippingRequestDetail shippingDetail in shippingRequestDetails)
                {
                    OrderDetail detail = new OrderDetail();
                    //Inventory inventory = inventoryRepository.findInventoryByBarCode(shippingDetail.inventoryId);
                    //if (inventory != null)
                    //{
                    //    detail.quantity = shippingDetail.quantity.ToString();
                    //    detail.unit = inventory.unit;
                    //    detail.inventoryName = inventory.name;
                    //    detais.Add(detail);
                    //}
                    detail.quantity = shippingDetail.quantity.ToString();
                    detail.unit = shippingDetail.invUnit;
                    detail.inventoryName = shippingDetail.invName;
                    detail.inventorystd = shippingDetail.invStd;
                    detail.BatchCode = shippingDetail.batchCode;
                    detail.VDate = shippingDetail.vDate;
                    detais.Add(detail);
                  
                }
                ViewData["shippingRequestDetail"] = detais;
            }
            return View();
        }

    }
}
